<?php
$login="fournisseur1";

function AfficherForm1() {
   echo '<h2>Choisir votre produit</h2><form method="post" action="' . htmlentities($_SERVER['PHP_SELF']).'
   	">
  	<table>
        <tr>
          <td>Produit:</td> 
          <td><input type="text" name="label" size="30" /></td> 
        </tr>
                  
        <tr>
          <td>Quantité:</td> 
          <td><input type="text" name="qte" size="3" /></td> 
        </tr>
        
        <tr>
          <td colspan="2"><input type="submit" name="subf1" value="Submit" /></td> 
        </tr>
      </table>
    </form>';
 
}

function AfficherForm2($label, $quantite, $prix, $login) {
   echo '<h2>Valider votre produit</h2><form method="post" action="' . htmlentities($_SERVER['PHP_SELF']).'
   	">
  	<table>
        <tr>
          <td>Produit:</td> 
          <td><input type="text" name="label" size="30" value="'.$label.'"/></td> 
        </tr>
                  
        <tr>
          <td>Quantité:</td> 
          <td><input type="text" name="qte" size="3"  value="'.$quantite.'"/></td> 
        </tr>
        
        <tr>
          <td colspan="2"><input type="submit" name="subf2" value="Submit" /></td> 
        </tr>
      </table>
      <input type="hidden" name="prixUnitaire"  value="'.$prix.'"/>
      <input type="hidden" name="login"  value="'.$login.'"/>
    </form>';
 
}

function debut() {echo "<html><head></head><body>";  }
  
function fin() {echo "</body></html>";   }
  if (!isset($_POST['subf1']) and !isset($_POST['subf2'])) {
	debut();
	afficherForm1();
	fin();
	exit(0);
  }
  if (isset($_POST['subf1'])) {
    debut();
	
	// POST submission, validate input
    if (trim($_POST['label']) == '') {
      die('ERREUR: Pas de label');
    }
    if (trim($_POST['qte']) == '') {
      die('ERREUR: Pas de quantité');
    }
    afficherForm2($_POST['label'], $_POST['qte'], "10", $login);
    fin();
    exit(0);
  }
  if (isset($_POST['subf2'])) {
  	debut();
	echo "<H2>JE VALIDE:</H2><pre>";
  	echo "\n * Login:". $_POST['login'];
  	echo "\n * Produit:". $_POST['label'];
  	echo "\n * Quantité:". $_POST['qte'];  	  	
  	echo "\n * prixUnitaire:". $_POST['prixUnitaire'];
  	echo "\n * prix Total:". $_POST['prixUnitaire']*$_POST['qte'];
  	echo "</pre>";
  	fin();
  }
?>   
